package online.westonline.com.westonline.ui;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Chronometer;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.west.westclient.Constants;
import com.gcssloop.widget.RCRelativeLayout;
import com.sj.emoji.EmojiBean;
import com.tangxiaolv.telegramgallery.GalleryActivity;
import com.tangxiaolv.telegramgallery.GalleryConfig;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.jpush.im.android.api.JMessageClient;
import cn.jpush.im.android.api.callback.GetUserInfoCallback;
import cn.jpush.im.android.api.content.ImageContent;
import cn.jpush.im.android.api.content.TextContent;
import cn.jpush.im.android.api.content.VoiceContent;
import cn.jpush.im.android.api.enums.ContentType;
import cn.jpush.im.android.api.enums.ConversationType;
import cn.jpush.im.android.api.event.MessageEvent;
import cn.jpush.im.android.api.event.MessageReceiptStatusChangeEvent;
import cn.jpush.im.android.api.model.Conversation;
import cn.jpush.im.android.api.model.Message;
import cn.jpush.im.android.api.model.UserInfo;
import cn.jpush.im.api.BasicCallback;
import online.westonline.com.westonline.MyApplication;
import online.westonline.com.westonline.R;
import online.westonline.com.westonline.adapter.im.AppsAdapter;
import online.westonline.com.westonline.adapter.im.ChatListAdpter;
import online.westonline.com.westonline.adapter.im.MyAppsAdpter;
import online.westonline.com.westonline.base.BaseActivity;
import online.westonline.com.westonline.utils.SimpleCommonUtils;
import online.westonline.com.westonline.utils.ToastUtils;
import online.westonline.com.westonline.utils.UiUtlis;
import pub.devrel.easypermissions.EasyPermissions;
import sj.keyboard.XhsEmoticonsKeyBoard;
import sj.keyboard.data.EmoticonEntity;
import sj.keyboard.interfaces.EmoticonClickListener;
import sj.keyboard.widget.EmoticonsEditText;
import sj.keyboard.widget.FuncLayout;

public class ChatActivity extends BaseActivity implements EasyPermissions.PermissionCallbacks {


    @BindView(R.id.tv_topbar_title)
    TextView tvTopbarTitle;
    @BindView(R.id.tv_topbar_title_center)
    TextView tvTopbarTitleCenter;
    @BindView(R.id.img_toolbar_menu)
    ImageView imgToolbarMenu;
    @BindView(R.id.tv_topbar_menu)
    TextView tvTopbarMenu;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.lv_chat)
    RecyclerView lvChat;
    @BindView(R.id.ek_bar)
    XhsEmoticonsKeyBoard ekBar;
    @BindView(R.id.ra_record_layout)
    RCRelativeLayout raRecordLayout;
    @BindView(R.id.ch_record_time)
    Chronometer chRecordTime;
    private ChatListAdpter chatListAdpter;
    //模式
    private boolean mode;
    //用户key
    private String user_appkey;
    //目标用户id
    private String target_user_id;
    //目标群组id
    private long group_id;
    private Conversation mConv;
    //消息体
    private Message message;
    //当前messageList
    private List<Message> messageList = new ArrayList<>();
    private List<String> photos = new ArrayList<>();
    //录音器
    private MediaRecorder mMediaRecorder;
    //播放器
    private MediaPlayer mediaPlayer;
    private File mRecAudioFile;
    private String recorde_path = MyApplication.getContext().getFilesDir() + "/Voice";
    private int cast_time;
    private int ALL_READ=0x12412;
    //当前点击的位置
    private int now_click_pos;
    private Handler time_handler = new Handler();
    private Handler myHnadler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(android.os.Message msg) {
            if (msg.what == PLAY_RECORD) {
                int msgid = messageList.get(now_click_pos).getId();
                chatListAdpter.playItem(record_time, now_click_pos, msgid);
            }
            if (msg.what == ALL_READ)
            {
                //设置已读完成
                mConv.setUnReadMessageCnt(0);
                //更新列表
                chatListAdpter.setMessageList(messageList);
                chatListAdpter.notifyDataSetChanged();
            }
            return true;
        }
    });
    private int RECORD = 100456;
    private int PLAY_RECORD = 20465465;
    private int record_time;
    //语音识别结果监听
    private boolean isget = false;
    private boolean timestop = false;
    private Runnable runnable_time;

    /**
     * 格式化显示playtime
     *
     * @param play_time
     * @return
     */
    private String playTimeFormat(int play_time) {
        String result = null;
        if (play_time < 10) {
            result = "00" + ":0" + play_time;
        }
        if (play_time >= 10) {
            result = "00:" + play_time;
            if (play_time == 60) {
                result = "01:00";
            }
            if (play_time > 60) {
                int minute = play_time / 60;
                int scend = play_time % 60;
                if (minute < 10) {
                    if (scend < 10) {
                        result = "0" + minute + ":" + "0" + scend;
                    }
                    if (scend > 10) {
                        result = "0" + minute + ":" + scend;
                    }
                }
                if (minute > 10) {
                    if (scend < 10) {
                        result = minute + ":" + "0" + scend;
                    }
                    if (scend > 10) {
                        result = minute + ":" + scend;
                    }
                }
            }
        }
        return result;
    }

    @Override
    protected void initview() {
        //初始化toolbar
        //tvTopbarTitleCenter.setText("目标");
        //tvTopbarTitleCenter.setTextColor(Color.BLACK);
        //tvTopbarMenu.setText("语音识别(点击开始)");
        tvTopbarMenu.setTextColor(UiUtlis.getColor(R.color.BlueTheme));
        toolbar.setBackgroundColor(UiUtlis.getColor(R.color.colorAppTheme));
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_keyboard_arrow_left_blue_500_24dp);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        //初始化recyclerview
        initrecyclerview();
        //初始化输入框
        initEmoticonsKeyBoardBar();
        //各种事件
        initsession();
    }

    private void initsession() {


       /*
        //图片点击
        chatListAdpter.setImageClickListener(new ChatListAdpter.onImageClickListener() {
            @Override
            public void ImageClick(int pos, String path) {
                Bundle bundle = new Bundle();
                bundle.putString("path", path);
                startActivityWithBundle(ImageActivity.class, false, bundle);
            }
        });
        //声音点击
        chatListAdpter.setVoiceClickListener(new ChatListAdpter.onVoiceClickListener() {
            @Override
            public void VoiceClick(int pos, String path, int time) {
                now_click_pos = pos;
                //计时注意
                try {
                    record_time = time;
                    mediaPlayer.reset();
                    mediaPlayer.setDataSource(path);
                    mediaPlayer.prepareAsync();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        });
        //播放相关
        mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                if (mediaPlayer != null) {
                    timer_play = new Timer();
                    mediaPlayer.start();
                    //启动定时任务
                    timer_play.schedule(new TimerTask() {
                        @Override
                        public void run() {
                            if (record_time != 0) {
                                record_time -= 1;
                                android.os.Message message = new android.os.Message();
                                message.what = PLAY_RECORD;
                                myHnadler.sendMessage(message);
                                myHnadler.obtainMessage();
                            }
                        }
                    }, 1000);
                }
            }
        });
        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                if (mediaPlayer != null) {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                }
            }
        });
        //语音识别
        tvTopbarMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isget) {
                    stop();
                    return;
                }
                tvTopbarMenu.setText("请等待自动识别完成");
                arc.registerListener(eventListener);
                startLink();
                isget = true;
            }
        });
        */
    }

    @Override
    protected void onStart() {
        super.onStart();
        //开始监听
        JMessageClient.registerEventReceiver(this);
    }

    private void initrecyclerview() {
        chatListAdpter = new ChatListAdpter(mConv);
        lvChat.setLayoutManager(new LinearLayoutManager(this));
        lvChat.setAdapter(chatListAdpter);
        parseData();
    }

    /**
     * 初始化
     */
    private void parseData() {
        chatListAdpter.setMessageList(messageList);
        chatListAdpter.notifyDataSetChanged();
        //先滚动到最后一位
        lvChat.scrollToPosition(messageList.size() - 1);

    }

    /**
     * 更新列表
     */
    private void updateData(Message message) {
        messageList.add(message);
        chatListAdpter.notifyItemInserted(messageList.size() - 1);
        //更新已读
        readMessage();
        if (!isSlideToBottom(lvChat)) {
            //没有到底部
            //吐司提示
        } else {
            //滚动到最后一位
            lvChat.scrollToPosition(messageList.size() - 1);
        }

    }

    /***
     * 计算距离是否到了底部
     * @param recyclerView
     * @return
     */
    public boolean isSlideToBottom(RecyclerView recyclerView) {
        if (recyclerView == null) {
            return false;
        }
        if (recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset()
                >= recyclerView.computeVerticalScrollRange())
            return true;
        return false;
    }

    @SuppressLint("ClickableViewAccessibility")
    private void initEmoticonsKeyBoardBar() {
        raRecordLayout.setVisibility(View.GONE);
        MyAppsAdpter appsAdpter = new MyAppsAdpter(this);
        SimpleCommonUtils.initEmoticonsEditText(ekBar.getEtChat());
        ekBar.setAdapter(SimpleCommonUtils.getCommonAdapter(this, emoticonClickListener));
        ekBar.addFuncView(appsAdpter);
        ekBar.addOnFuncKeyBoardListener(new FuncLayout.OnFuncKeyBoardListener() {
            @Override
            public void OnFuncPop(int i) {
                //滚动到最底部
                lvChat.scrollToPosition(messageList.size() - 1);
            }

            @Override
            public void OnFuncClose() {

            }
        });
        //加号部分的适配器
        //ekBar.addFuncView(new SimpleAppsGridView(this));
        appsAdpter.getAdapter().setAppsClickListener(new AppsAdapter.AppsClickListener() {
            @Override
            public void Click(String s) {
                if (s.equals("图片")) {
                    //询问图片权限
                    askImagePermission();
                }
            }
        });
        ekBar.getEtChat().setOnSizeChangedListener(new EmoticonsEditText.OnSizeChangedListener() {
            @Override
            public void onSizeChanged(int w, int h, int oldw, int oldh) {
                //滚动到底部
                lvChat.scrollToPosition(messageList.size() - 1);

            }
        });
        ekBar.getBtnSend().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //发送聊天消息
                //走这个方法发送都是文本
                //暂时组织为文本
                String content = ekBar.getEtChat().getText().toString();
                if (!TextUtils.isEmpty(content)) {
                    TextContent textContent = new TextContent(content);
                    chatListAdpter.updateTextMsg(textContent, lvChat);
                }
                //发送按钮点击事件
                ekBar.getEtChat().setText("");
            }
        });
        //自定义的+号图标
        /*
        ekBar.getEmoticonsToolBarView().addFixedToolItemView(false, R.drawable.ic_add_grey_500_24dp, null, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        */
        ekBar.getEmoticonsToolBarView().addToolItemView(R.drawable.ic_settings_blue_500_24dp, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        //切换语音输入
        ekBar.getBtnVoice().setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                //初始化计时器(录制时间监听器)

                //每一个实例只能监听一个和一次
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        raRecordLayout.setVisibility(View.VISIBLE);
                        //按下
                        cast_time=0;
                        chRecordTime.setBase(SystemClock.elapsedRealtime());
                        chRecordTime.start();
                        askVoicePermission();
                        timestop = false;
                        break;
                    case MotionEvent.ACTION_UP:
                        timestop = true;
                        int temp0 = Integer.parseInt(chRecordTime.getText().toString().split(":")[0]);
                        int temp1 =Integer.parseInt(chRecordTime.getText().toString().split(":")[1]);
                        cast_time=temp0*60+temp1;
                        chRecordTime.stop();
                        chRecordTime.setBase(SystemClock.elapsedRealtime());
                        raRecordLayout.setVisibility(View.GONE);
                        stopRecord();

                        //组织content
                        try {
                            VoiceContent voiceContent = new VoiceContent(mRecAudioFile, cast_time);
                            chatListAdpter.updateVoiceMsg(voiceContent, lvChat);
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                        break;

                }
                return true;
            }
        });
    }

    /**
     * 询问录音条件
     */
    private void askVoicePermission() {
        String[] per = new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE};
        if (EasyPermissions.hasPermissions(this, per)) {
            //执行
            startRecord(recorde_path);
        } else {
            EasyPermissions.requestPermissions(this, "发语音之前请赋予权限", 54654, per);
        }

    }

    EmoticonClickListener emoticonClickListener = new EmoticonClickListener() {
        @Override
        public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) {


            if (isDelBtn) {
                //如果是删除就清掉输入框
                SimpleCommonUtils.delClick(ekBar.getEtChat());
            } else {
                if (o == null) {
                    return;
                }
                if (actionType == Constants.EMOTICON_CLICK_BIGIMAGE) {
                    if (o instanceof EmoticonEntity) {
                        //大表情图,会直接发送至页面
                        //OnSendImage(((EmoticonEntity)o).getIconUri());
                    }
                } else {
                    String content = null;
                    if (o instanceof EmojiBean) {
                        content = ((EmojiBean) o).emoji;
                    } else if (o instanceof EmoticonEntity) {
                        content = ((EmoticonEntity) o).getContent();
                    }

                    if (TextUtils.isEmpty(content)) {
                        return;
                    }
                    int index = ekBar.getEtChat().getSelectionStart();
                    Editable editable = ekBar.getEtChat().getText();
                    editable.insert(index, content);
                }
            }
        }
    };

    /**
     * 开始录音
     *
     * @param fullFileName 录音输出的文件名（绝对路径）
     */
    public void startRecord(String fullFileName) {

        if (fullFileName == null) {
            return;
        }
        try {
            //每次进入这里重置
            cast_time = 0;
            mMediaRecorder = new MediaRecorder();
            mMediaRecorder.reset();
            /* ②setAudioSource/setVedioSource*/
            mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);//设置麦克风
            /* ②设置输出文件的格式：THREE_GPP/MPEG-4/RAW_AMR/Default
             * THREE_GPP(3gp格式，H263视频/ARM音频编码)、MPEG-4、RAW_AMR(只支持音频且音频编码要求为AMR_NB)
			 * */
            mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            /* ②设置音频文件的编码：AAC/AMR_NB/AMR_MB/Default */
            mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

            mRecAudioFile = new File(recorde_path,
                    new DateFormat().format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".amr");
            //判断路径是否存在
            File director = new File(recorde_path);
            if (director.exists()) {
                mRecAudioFile.createNewFile();

            } else {
                director.mkdir();
                director.mkdirs();
                mRecAudioFile.createNewFile();
            }
            Log.e("路径", mRecAudioFile.getPath());
            mMediaRecorder.setOutputFile(mRecAudioFile.getAbsolutePath());
            mMediaRecorder.prepare();
            mMediaRecorder.start();

            //启动timer
        } catch (Exception e) {
            e.printStackTrace();
            try {
                mMediaRecorder.stop();
                mMediaRecorder.reset();
                mMediaRecorder.release();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            mMediaRecorder = null;

        }
    }


    /**
     * 停止录音
     */
    public void stopRecord() {
        if (mMediaRecorder != null) {
            	/* 停止录音 */
            //mMediaRecorder.stop();
			/*释放MediaRecorder */
            mMediaRecorder.reset();

        }

    }

    private static final int BASE = 1;

    /**
     * 获取录音的声音分贝值
     *
     * @return
     */
    public int getDB() {
        double ratio = (double) mMediaRecorder.getMaxAmplitude() / BASE;
        double db = 0;// 分贝
        if (ratio > 1)
            db = 20 * Math.log10(ratio);
        //db为分贝值
        return (int) db;
    }

    /**
     * 问权限
     */
    private void askImagePermission() {
        String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
        if (EasyPermissions.hasPermissions(this, permissions)) {
            //打开相册
            openGrally();
        } else {
            EasyPermissions.requestPermissions(this, "申请读取相册权限", 10, permissions);
        }
    }

    /**
     * 打开相册
     */
    private void openGrally() {
        GalleryConfig config = new GalleryConfig.Build()
                .singlePhoto(false)
                //最多9张
                .limitPickPhoto(9)
                .hintOfPick("最多只能选择9张图片")
                .filterMimeTypes(new String[]{"image/jpeg/png/gif/jpg"})
                .build();
        GalleryActivity.openActivity(ChatActivity.this, 15, config);
    }

    @Override
    protected void initdata() {
        //
        JMessageClient.setNotificationFlag(JMessageClient.FLAG_NOTIFY_DISABLE);
        //播放器初始化
        mediaPlayer = new MediaPlayer();
        //初始化聊天框
        initchat();
        //初始化数据
        //模式
        mode = getIntent().getExtras().getBoolean(Constants.MODE, false);
        //私聊id
        target_user_id = getIntent().getExtras().getString(Constants.SINGLE_ID);
        //私聊appkey
        user_appkey = getIntent().getExtras().getString(Constants.TARGET_APPKEY);
        //群组id
        group_id = getIntent().getExtras().getLong(Constants.GROUP_ID);
        //获取聊天记录
        initchathistory();
    }


    /**
     * 获取聊天记录
     */
    private void initchathistory() {
        //1.聊天记录分为私聊和群聊
        if (!mode) {
            //先获取私聊的会话
            mConv = JMessageClient.getSingleConversation(target_user_id, user_appkey);
            //如果没有就创建
            if (mConv == null) {
                mConv = Conversation.createSingleConversation(target_user_id, user_appkey);
            }
            //获取目标nickname
            JMessageClient.getUserInfo(target_user_id, user_appkey, new GetUserInfoCallback() {
                @Override
                public void gotResult(int i, String s, UserInfo userInfo) {
                    Log.e("信息",i+":"+s);
                    if (userInfo != null) {
                        //更新顶部标题
                        tvTopbarTitleCenter.setTextColor(Color.BLACK);
                        tvTopbarTitleCenter.setText(userInfo.getNickname());
                    }
                }
            });
            //获取聊天记录
            messageList = mConv.getAllMessage();
            //设置消息已读
            readMessage();

        } else {
            //群聊
        }
    }

    /**
     * 标记消息已读
     */
    private void readMessage() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (final Message message : messageList) {
                    //1.消息未读
                    //2.不是自己的消息
                    if (!message.haveRead() && !message.getFromUser().getUserName().equals(JMessageClient.getMyInfo().getUserName())) {
                        message.setHaveRead(new BasicCallback() {
                            @Override
                            public void gotResult(int i, String s) {
                                if (i == 0) {
                                    Log.e("message", "标记已读成功");

                                }
                            }
                        });

                    }
                }
                //通知界面变化
                android.os.Message message = new android.os.Message();
                message.what = ALL_READ;
                myHnadler.sendMessage(message);
                myHnadler.obtainMessage();
            }
        }).start();
    }

    private void initchat() {

    }

    @Override
    protected int setlayout() {
        return R.layout.activity_chat;
    }

    //-----------------------------------------------------极光聊天部分---------------------------------

    /**
     * 接收到消息
     *
     * @param event
     */
    public void onEventMainThread(MessageEvent event) {

        Message new_message = event.getMessage();
        if (new_message.getContentType() == ContentType.eventNotification) {
            //通知类型
        }
        if (new_message.getTargetType() == ConversationType.single) {
            //暂时只管单人聊天
            updateData(new_message);
        }

    }

    /**
     * 消息已读事件
     */
    public void onEventMainThread(MessageReceiptStatusChangeEvent event) {
        List<MessageReceiptStatusChangeEvent.MessageReceiptMeta> messageReceiptMetas = event.getMessageReceiptMetas();
        for (MessageReceiptStatusChangeEvent.MessageReceiptMeta meta : messageReceiptMetas) {
            long serverMsgId = meta.getServerMsgId();
            int unReceiptCnt = meta.getUnReceiptCnt();
            chatListAdpter.setUpdateReceiptCount(serverMsgId, unReceiptCnt);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        JMessageClient.exitConversation();
        JMessageClient.unRegisterEventReceiver(this);
        JMessageClient.setNotificationFlag(JMessageClient.FLAG_NOTIFY_DEFAULT);
        stopRecord();
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            mediaPlayer.release();
        }

    }

    /**
     * 获取图片路径
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //获取选中的照片路径
        if (data == null) {
            //点了取消
            return;
        }
        //先清空
        photos.clear();
        if (photos.size() > 0) {
            photos.addAll((List<String>) data.getSerializableExtra(GalleryActivity.PHOTOS));
        } else {
            photos = (List<String>) data.getSerializableExtra(GalleryActivity.PHOTOS);
        }

        if (photos.size() > 0 && photos.size() < 10) {
            //组合消息体
            formatImgContent();
        }
    }

    /**
     * 组织图片
     */
    private void formatImgContent() {
        try {
            int before_size = messageList.size();
            for (String path : photos) {
                //图片发送
                ImageContent imageContent = new ImageContent(new File(path));
                Message message = mConv.createSendMessage(imageContent);
                updateData(message);
            }
            //开始刷新图片标记
            int now_size = messageList.size();
            int start_pos = now_size - before_size;
            chatListAdpter.checkSendingImgMsg(start_pos);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onPermissionsGranted(int requestCode, List<String> perms) {
        if (requestCode == 10) {
            openGrally();
        }
        if (requestCode == 54654) {
            startRecord(recorde_path);
        }

    }


    @Override
    public void onPermissionsDenied(int requestCode, List<String> perms) {
        ToastUtils.showToast("权限不足");
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }



}
